package io.github.ilkgunel.dao;

import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCursor;
import io.github.ilkgunel.database.AccessMongoDB;
import io.github.ilkgunel.pojo.Student;
import io.github.ilkgunel.pojo.Teacher;
import org.bson.Document;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class teacherfind {
    public List<Teacher> find()
    {
        List<Teacher> list = new ArrayList<>();
        //FindIterable<Document> result = getMongoDatabase().getCollection("Records").find(new Document("name","Can"));
        AccessMongoDB accessMongoDB = new AccessMongoDB();



        FindIterable<Document> result = accessMongoDB.getCollection("teacher").find();


        MongoCursor<Document> cursor = result.iterator();
        while (cursor.hasNext()) {

            Document document = cursor.next();


            String temp;
            Teacher s=new Teacher();
            s.set_id(document.get("_id").toString());

            System.out.println(document.get("_id").toString());
            s.setTid(document.get("tid").toString());
            s.setName(document.get("name").toString());
            s.setSex( document.get("sex").toString());

            temp= new BigDecimal((document.get("age")).toString()).toPlainString();
            s.setAge((int)Double.parseDouble( temp));


            s.setDname( document.get("dname").toString());


            list.add(s);
        }
        return list;
    }
}
